package com.cci.kangdao.service.impl;

import com.cci.kangdao.dao.CommonReasonTDao;
import com.cci.kangdao.dao.model.CommonReasonT;
import com.cci.kangdao.dto.ReasonResponse;
import com.cci.kangdao.service.CommonReasonService;
import com.cci.kangdao.utilTool.BeanUtils;
import com.cci.kangdao.utilTool.CollectionUtils;
import com.cci.kangdao.utilTool.ParameterTool;
import com.cci.kangdao.utilTool.RequestContextHolder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author William Du
 * @date 2020/4/29
 */
@Service
public class CommonReasonServiceImpl implements CommonReasonService {

    @Resource
    private CommonReasonTDao commonReasonTDao;

    @Override
    public List<CommonReasonT> getReasonList(String channel, Integer category, Integer type) {
        CommonReasonT queryReason = new CommonReasonT();
        queryReason.setChannel(channel);
        queryReason.setCategory(category);
        queryReason.setType(type);
        queryReason.setFlag(0);
        List<CommonReasonT> reasonTList = commonReasonTDao.selectListByCondition(queryReason);
        return reasonTList;
    }

    @Override
    public void returnReasonList(String channel, Integer category, Integer type) {
        HttpServletResponse response = RequestContextHolder.getResponse();
        Map<String,Object> data = new HashMap<>(1);
        List<CommonReasonT> reasonTList = getReasonList(channel, category, type);
        if(CollectionUtils.isNotEmpty(reasonTList)){
            List<ReasonResponse> reasonResponseList = BeanUtils.convertList(reasonTList,ReasonResponse.class);
            data.put("reasonList",reasonResponseList);
        }else{
            data.put("reasonList",new ArrayList<>(0));
        }
        ParameterTool.writeSuccessResponse(response,data);
    }
}
